﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace collection_stack_practice
{
    class Program
    {
        static void Main(string[] args)
        {
         //将整数1到20放入栈中，并输出其中的偶数。。。
            Stack stack1 = new Stack();
            Stack stack2 = new Stack();

            for (int i = 1; i <= 20; i++)
            {
                stack1.Push(i);
              
            }
            Console.WriteLine("栈中的数有：");
            foreach(int item in stack1)
            {
                Console.Write(item+" ");
            }
            Console.WriteLine();
            
            while (stack1.Count !=0)
            {
                int a = Convert.ToInt32(stack1.Peek());
                
                if ( a % 2 == 0)
                {
                    stack2.Push(a);
                   

                }
                stack1.Pop();


            }

            Console.WriteLine("其中的偶数：");
            foreach (int item in stack2)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
    }
}
